import { createRouter, createWebHistory } from 'vue-router';

// 使用 import.meta.glob 动态导入所有页面组件  
const pages = import.meta.glob('../pages/**/*.vue');

const routers = Object.entries(pages).map(item => {
    let name = item[0].replace('../pages', '').replace('/index.vue', '')
    let path = item[0].replace('../pages', '').replace('/index.vue', '')
    return {
        path,
        name,
        component: item[1],
    }
})

const router = createRouter({
    history: createWebHistory(),
    routes: [
        {
            path: '/',
            redirect: '/home',
        },
        ...routers,
    ],
});

console.log();


export default router;